//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	FormsSource.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System.Collections.Generic;

namespace Smart.Common.Forms
{
	/// <summary>
	/// Forms template source (load forms template source)
	/// </summary>
	public abstract class FormsSource
	{
		/// <summary>
		/// Forms context
		/// </summary>
		public FormsContext Ctx { get; set; }

		/// <summary>
		/// Detect metadata for entity
		/// </summary>
		public abstract MetaList DetectMetaList();

		/// <summary>
		/// Detect form type (using context)
		/// </summary>
		public abstract string DetectFormsType();

		/// <summary>
		/// Load form definition by <paramref name="formsTypeName"/>
		/// </summary>
		public abstract object LoadFormsDefinition(string formsTypeName);

		/// <summary>
		/// Load values into context
		/// </summary>
		public virtual void LoadValuesToCtx(IDictionary<string, object> values)
		{
			if (values == null)
				return;

			var ctxValues = Ctx.Values;

			foreach (var kvp in values)
				ctxValues[kvp.Key] = kvp.Value;
		}

		/// <summary>
		/// Load entity values into context
		/// </summary>
		public abstract void LoadEntityValuesToCtx();

		/// <summary>
		/// Save entity values from context
		/// </summary>
		public abstract bool SaveEntityValuesFromCtx();

		/// <summary>
		/// Forms template source (load forms template source)
		/// </summary>
		protected FormsSource(FormsContext ctx)
		{
			Ctx = ctx;
		}
	}
}